package com.cogent.dynamicform.form.impl;

import java.util.HashMap;

import com.cogent.common.util.MapUtil;
import com.cogent.common.util.StringUtil;
import com.cogent.dynamicform.domain.BaseFormColumnDomain;
import com.cogent.dynamicform.domain.FormColumnDomain;
import com.cogent.dynamicform.form.AbstractDynamicForm;

public class QueryHiddenDynamicFormImpl extends AbstractDynamicForm {
	
	public String genInputField(FormColumnDomain formColumnDomain, HashMap formMap) {
		StringBuffer str = new StringBuffer();
		String name = formColumnDomain.getName();
		if(name.indexOf("~") > 0)
			name = name.substring(name.indexOf("~") + 1);
		str.append("<input type=\"hidden\" name=\"").append(formColumnDomain.getName()).append("\" id=\"").append(formColumnDomain.getName())
			.append("\" value=\"").append(MapUtil.getStringValue(formMap, name)).append("\"/>");
		str.append("<input type=\"text\" id=\"").append(formColumnDomain.getName()).append("value\" name=\"")
			.append(formColumnDomain.getName()).append("value");
		String className = "input_middle";
		if(!StringUtil.isEmpty(formColumnDomain.getShowclass()))
			className = formColumnDomain.getShowclass();
		str.append("\" class=\"").append(className).append("\" maxlength=\"120\"").append(" value=\"")
			.append(MapUtil.getStringValue(formMap, name + "value")).append("\" readonly=\"readonly\"")
			.append("/>");
		
		return str.toString();
	}
	
	public String getShowValue(BaseFormColumnDomain formColumnDomain, HashMap formMap) {
		if(formColumnDomain.getShowtype() == 1)
			return "&nbsp;";
		String name = formColumnDomain.getName();
		if(name.indexOf("~") > 0)
			name = name.substring(name.indexOf("~") + 1);
		
		return MapUtil.getStringValue(formMap, name + "value", "&nbsp;");
	}
}
